﻿using System;
using System.Data;

namespace Shuba.Web.master
{
    public partial class summary_period_excel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string unit_code = Request["unit_code"];
            
            if (unit_code == "ALL") unit_code = "%";

            //if (unit_code == Session["UnitID"].ToString() || IsValidUser(unit_code))
            //{
                try
                {
                    string sYear = Request["tahun"];
                    string sMonth = Request["bulan"];
                    string region_code = Request["region_code"];
                    string cluster_code = Request["cluster_code"];
                    DateTime StartDate = Convert.ToDateTime(Request["start"]);
                    DateTime EndDate = Convert.ToDateTime(Request["end"]);

                    if (region_code == "ALL") region_code = "%";
                    if (cluster_code == "ALL") cluster_code = "%";

                    Shuba.Business.Reports _Report = new Shuba.Business.Reports();
                    DataSet ds = _Report.RPT_PERIOD_PERFORMANCE(region_code, cluster_code, unit_code, StartDate, EndDate);

                    Response.Clear();
                    Response.Buffer = true;
                    Response.ContentType = "application/vnd.ms-excel";

                    rep1.DataSource = ds;
                    rep1.DataBind();
                }
                catch (Exception ex)
                {
                    Response.Write("<script>alert('" + ex.Message.Replace("'", "").Replace('"', ' ') + "');window.close();</script>");
                    Response.End();
                }
            //}
            //else
            //{
            //    Response.Write("<script>alert('You don`t have right to enter this page');window.close();</script>");
            //    Response.End();
            //}
        }
    }
}
